/*
 * @Author: daidai
 * @Date: 2021-12-23 11:18:37

 * @LastEditTime: 2024-03-28 16:07:20
 * @FilePath: \web-pc-svn\src\api\modules\index.js
 */

import {GETNOBASE} from "./api";
export * from "./modules/index"
export {GETNOBASE}

import { onMounted, reactive, ref } from "vue";
import { useRouter } from 'vue-router';
import {useLoginStore} from "@/stores/login";
import {storeToRefs} from 'pinia'
import axios from "axios";
// import { jwtDecode } from 'jwt-decode';

const loginStore = useLoginStore();
const {password,username} = storeToRefs(loginStore);
const message = ref('');

const router = useRouter();

// 登录处理函数
export const login = async () => {
    // error.value = ''; // 清空错误信息
    try {
        const response = await axios.post('http://longbhu.cn:8033/api/login', {
            username: username.value,
            password: password.value,
        });
        const token = response.data.token;
        localStorage.setItem('token', token);
        ElMessage.success('登录成功');
        // 可以在登录成功后进行跳转或者其他操作
        setTimeout(async () => {
            await router.push('/homepage');
        },200)
        username.value = '';
        password.value = '';
    } catch (err) {
        ElMessage.error("用户名或密码错误");
    }
};